<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateFileTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('file', ['comment' => '文件', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('admin_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '管理员'])
            ->addColumn('url', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '地址'])
            ->addColumn('image_width', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '图片宽度'])
            ->addColumn('image_height', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '图片高度'])
            ->addColumn('group', 'string', ['limit'  =>  60, 'default' => 'default', 'comment' => '文件分组'])
            ->addColumn('extension', 'string', ['limit'  =>  60, 'null' => true, 'default' => null, 'comment' => '后缀'])
            ->addColumn('filename', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '文件名'])
            ->addColumn('storage', 'string', ['limit'  =>  60, 'null' => true, 'default' => null, 'comment' => '存储驱动'])
            ->addColumn('filesize', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '文件大小'])
            ->addColumn('mimetype', 'string', ['limit'  =>  191, 'null' => true, 'default' => null, 'comment' => 'mime类型'])
            ->addColumn('file_md5', 'string', ['limit'  =>  60, 'null' => true, 'default' => null, 'comment' => '文件 md5'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('extension')
            ->addIndex('mimetype')
            ->addIndex('group')
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('file');
        $table->drop();
    }
}
